﻿using System.ComponentModel;

namespace Marmat.Forms.Views
{
    namespace Grid
    {
        public partial class Band
        {
            internal DevExpress.XtraGrid.Views.BandedGrid.GridBand _band;
            internal BaseGrid _grid;
            internal Band _parent;

            public Band()
            {
                this._band = new DevExpress.XtraGrid.Views.BandedGrid.GridBand();
                this._band.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                this._band.AppearanceHeader.TextOptions.VAlignment = DevExpress.Utils.VertAlignment.Center;
                this._band.Tag = this;
                this._columns = new BandColumnCollection(this);
            }

            public string Name
            {
                get => this._band.Name;
                set
                {
                    this._band.Name = value;
                    this.SetCaption();
                }
            }

            public string Caption
            {
                get
                {
                    if (string.IsNullOrEmpty(this._Caption))
                        return this.Name;
                    return this._Caption;
                }
                set
                {
                    this._Caption = value;
                    this.SetCaption();
                }
            }

            private string _Caption;

            private void SetCaption()
            {
                if (!string.IsNullOrEmpty(this.Caption))
                {
                    this._band.Caption = this.Caption;
                }
                else
                {
                    this._band.Caption = this.Name;
                }
            }

            public Band Parent => this._parent;

            [Browsable(false)]
            [EditorBrowsable(EditorBrowsableState.Always)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            [Localizable(true)]
            [NotifyParentProperty(true)]
            [Category("数据")]
            [Description("返回 Table 的列集合")]
            public BandCollection Bands
            {
                get
                {
                    if (this._Bands is null)
                        this._Bands = new BandCollection(this._grid, this._band.Children);
                    return this._Bands;
                }
            }

            private BandCollection _Bands;

            [Browsable(false)]
            [EditorBrowsable(EditorBrowsableState.Always)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            [Localizable(true)]
            [NotifyParentProperty(true)]
            [Category("数据")]
            [Description("返回 Table 的列集合")]
            public BandColumnCollection Columns => this._columns;

            private BandColumnCollection _columns;

            [Browsable(false)]
            public BaseGrid Grid => this._grid;

        }
    }
}